package com.xyb.controller;

import com.xyb.entity.CourseTopic;
import com.xyb.service.TopicService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("topic")
public class TopicController {
    @Resource
    private TopicService topicService;

    @GetMapping("topic")
    public List<CourseTopic> getTopics() {
        List<CourseTopic> list = topicService.selectCourseTopicList();
        return list;
    }

    @PostMapping("topic")
    public String insertTopic(@RequestBody CourseTopic courseTopic) {
        return topicService.insertTopic(courseTopic);
    }

    @PutMapping("topic/{topicId}")
    public String updateTopic(@PathVariable("topicId") Long topicId,@RequestBody CourseTopic courseTopic) {
        courseTopic.setTopicId(topicId);
        return topicService.updateTopic(courseTopic);
    }

    @PutMapping("topic/order")
    public String updateTopicShowOrder(@RequestBody Long[] topicIds){
        return topicService.updateTopicShowOrder(topicIds);
    }

    @DeleteMapping("topic/{topicId}")
    public String deleteTopicByTopicId(@PathVariable("topicId") Long topicId) {
        return topicService.deleteTopicByTopicId(topicId);
    }

}
